package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import org.apache.dubbo.config.annotation.Service;
import org.mapstruct.Mapping;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 创建日期: 2022-01-20-16-41
 * author : XGQ
 * description:
 */
@Service
public class IProductCateServiceImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter productCateConverter;
    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {
        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();
        try {
            request.requestCheck();
            List<ItemCat> items = itemCatMapper.getProductCate(request.getSort());
            List<ProductCateDto> productCateDtoList = productCateConverter.items2Dto(items);
            allProductCateResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            allProductCateResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            allProductCateResponse.setProductCateDtoList(productCateDtoList);
        } catch (Exception e){
            e.printStackTrace();
            allProductCateResponse.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            allProductCateResponse.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
        }
        return allProductCateResponse;
    }
}
